
$(function () {                                                                     
    $(document).ready(function() {                                                  
        Highcharts.setOptions({                                                     
            global: {                                                               
                useUTC: false                                                       
            }                                                                       
        });                                                                         
        let path = window.location.href
        let typeName = path.split('?')[1].split('=')[1] 
        let typeNumber=typeName
        if(typeName==0) {
            typeName='王者荣耀'
        }
        else if(typeName==1) {
            typeName='英雄联盟'
        }
        else if(typeName==2) {
            typeName='荒野行动'
        }
        var chart;      

        $('#container').highcharts({                                                
            chart: {                                                                
                type: 'spline',                                                     
                animation: Highcharts.svg, // don't animate in old IE               
                marginRight: 10,                                                    
                events: {                                                           
                    load: function() {                                              
                        let userId
                        $.post(userInfoUrl, (res) => {
                            // $('#container').showLoading() 
                        userId=res.obj.fdId
                        if(typeNumber==0) {

                            let handel= setInterval(()=>{
                                 $.post('http://120.79.198.159/data/pushData',{gameName:'wzry'},(res)=>{
                                        // console.log(res);
                                        // console.log(Math.ceil(Math.random()*3))
                                        let data=JSON.stringify(res),
                                        m=data.split(':')[3].split('"')[1]
                                        clearInterval(handel)
                                        $('.online').text(m);
                                        $('.onlineNow').html(m);})
                            },100)
                            setInterval(function() {
                                    let m;
                                    $.post('http://120.79.198.159/data/pushData',{gameName:'wzry'},(res)=>{
                                        // console.log(res);
                                        // console.log(Math.ceil(Math.random()*3))
                                        let data=JSON.stringify(res),
                                        m=data.split(':')[3].split('"')[1]
                                        // console.log(m)
                                        $('.online').text(m);
                                        $('.onlineNow').html(m);
                                        var x = (new Date()).getTime(), // current time         
                                           y = m/10;                                  
                                        series.addPoint([x, y], true, true);
                                    })
                                },1000*Math.ceil(Math.random()*7))
                            
                            }   
                       
                       
                        if(typeNumber==1){
                            let handel= setInterval(()=>{
                                 $.post('http://120.79.198.159/data/pushData',{gameName:'yxlm'},(res)=>{
                                        // console.log(res);
                                        // console.log(Math.ceil(Math.random()*3))
                                        let data=JSON.stringify(res),
                                        m=data.split(':')[3].split('"')[1]
                                        clearInterval(handel)
                                        $('.onlineLol').text(m);
                                        $('.onlineNowLol').html(m);})
                            },100)
                            setInterval(function() {
                                    let m;
                                    $.post('http://120.79.198.159/data/pushData',{gameName:'yxlm'},(res)=>{
                                        // console.log(res);
                                        console.log(Math.ceil(Math.random()*3))
                                        let data=JSON.stringify(res),
                                        m=data.split(':')[3].split('"')[1]
                                        // console.log(m)
                                        $('.onlineLol').text(m);
                                        $('.onlineNowLol').html(m);
                                        var x = (new Date()).getTime(), // current time         
                                           y = m/10;                                  
                                        series.addPoint([x, y], true, true);
                                    })
                                },1000*Math.ceil(Math.random()*3))
                        }
                        
                       if(typeNumber==2){
                           let handel= setInterval(()=>{
                                 $.post('http://120.79.198.159/data/pushData',{gameName:'hyxd'},(res)=>{
                                        // console.log(res);
                                        // console.log(Math.ceil(Math.random()*3))
                                        let data=JSON.stringify(res),
                                        m=data.split(':')[3].split('"')[1]
                                        clearInterval(handel)
                                        $('.onlineChiji').text(m);
                                        $('.onlineNowChiji').html(m);})
                            },100)
                        setInterval(function() {
                                    let m;
                                    $.post('http://120.79.198.159/data/pushData',{gameName:'hyxd'},(res)=>{
                                        // console.log(res);
                                        // console.log(res);
                                        console.log(Math.ceil(Math.random()*3))
                                        let data=JSON.stringify(res),
                                        m=data.split(':')[3].split('"')[1]
                                        // console.log(m)
                                        $('.onlineChiji').text(m);
                                        $('.onlineNowChiji').html(m);
                                        var x = (new Date()).getTime(), // current time         
                                           y = m/10;                                  
                                        series.addPoint([x, y], true, true);
                                    })
                                },1000*Math.ceil(Math.random()*3))
                       }
                        })                                             
                        // set up the updating of the chart each second             
                        var series = this.series[0];                                
                        // setInterval(function() {                                    
                        //     var x = (new Date()).getTime(), // current time         
                        //         y = Math.random();                                  
                        //     series.addPoint([x, y], true, true);                    
                        // }, 1000); 
                        
                        
                    }                                                               
                }                                                                   
            },                                                                      
            title: {                                                                
                text: typeName                                            
            },                                                                      
            xAxis: {                                                                
                type: 'datetime',                                                   
                tickPixelInterval: 150                                              
            },                                                                      
            yAxis: {                                                                
                title: {                                                            
                    text: '在线人数'
                },                                                                  
                plotLines: [{                                                       
                    value: 0,                                                       
                    width: 1,                                                       
                    color: '#808080'                                                
                }]                                                                  
            },                                                                      
            tooltip: {                                                              
                formatter: function() {                                             
                        return '<b>'+ this.series.name +'</b><br/>'+                
                        Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
                        Highcharts.numberFormat(this.y, 2);                         
                }                                                                   
            },                                                                      
            legend: {                                                               
                enabled: false                                                      
            },                                                                      
            exporting: {                                                            
                enabled: false                                                      
            },                                                                      
            series: [{                                                              
                name: '在线人数',
                data: (function() {                                                 
                    // generate an array of random data                             
                    var data = [],                                                  
                        time = (new Date()).getTime(),                              
                        i;                                                          
                                                                                    
                    for (i = -19; i <= 0; i++) {                                    
                        data.push({                                                 
                            x: time + i * 2000,                                     
                            y:1312312*Math.ceil(Math.random()*5)
                        });                                                         
                    }                                                               
                    return data;                                                    
                })()                                                                
            }]                                                                      
        });                                                                         
    });                                                                             
                                                                                    
});                                                                                 